home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / misc / math / MathFX_src.lha / fx3cut.c < prev    next >
C/C++ Source or Header  |  1995-12-20  |  847b  |  39 lines

  1. /* Determines the point of intersection (cx,cy) between the line */
  2. /* joining (sx1,sy1) to (sx2,sy2) and the line joining */
  3. /* (su1,sv1) to (su2,sv2). */
  4.  
  5. #include "mathfx.h"
  6.  
  7.  
  8.  
  9. void fx3cut(sx1,sy1,sx2,sy2,su1,sv1,su2,sv2,cx,cy)
  10. int sx1, sy1, sx2, sy2, su1, sv1, su2, sv2, *cx, *cy;
  11. {
  12.       int x21, y21, u21, v21, yv1, xu1, a, b;
  13.             
  14.       x21 = sx2 - sx1;
  15.       y21 = sy2 - sy1;
  16.       u21 = su2 - su1;
  17.       v21 = sv2 - sv1;
  18.       yv1 = sy1 - sv1;
  19.       xu1 = sx1 - su1;
  20.  
  21.       a = x21 * v21 - y21 * u21;
  22.       if (a == 0) {
  23.         if (sx2 < su2) {
  24.           *cx = sx2;
  25.           *cy = sy2;
  26.         }
  27.         else {
  28.           *cx = su2;
  29.           *cy = sv2;
  30.         }
  31.         return;
  32.       }
  33.       else {
  34.         b = yv1 * u21 - xu1 * v21;
  35.         *cx = sx1 + (b * x21 + a/2) / a;
  36.         *cy = sy1 + (b * y21 + a/2) / a;
  37.       }
  38. }
  39.